<?php
namespace Arathi;

use Arathi\WeiboApi;
use Arathi\Weibo\Status;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

class WeiboClient
{
    private $logger;
    protected $api;
    protected $token;

    public function __construct($token)
    {
        $this->logger = new Logger('WeiboClient');
        $this->logger->pushHandler(new StreamHandler('logs/client.log', Logger::DEBUG));

        $this->token = $token;
        $this->api = new WeiboApi();
    }

    public function getPublicStatuses()
    {
        $statuses = array();
        $respMsgDecoded = $this->api->statuses_public_timeline($this->token);
        $respStatuses = $respMsgDecoded->statuses;
        foreach ($respStatuses as $respStatus)
        {
            $status = new Status($respStatus);
            $this->logger->debug($status->toString());
            $statuses[] = $status;
        }
        return $statuses;
    }
    
    public function getHomePageStatuses()
    {
        $statuses = array();
        $respMsgDecoded = $this->api->statuses_home_timeline($this->token);
        $respStatuses = $respMsgDecoded->statuses;
        foreach ($respStatuses as $respStatus)
        {
            $status = new Status($respStatus);
            $this->logger->debug($status->toString());
            $statuses[] = $status;
        }
        return $statuses;
    }
}
